<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${basePackage}.core.${moduleName}.infra.${className}Repository">
    <resultMap type="${basePackage}.core.${moduleName}.domain.${className}" id="${classObjectName}ResultMap">
    <#list fields as field>
        <#if field.fieldName == keyName>
        <id column="${keyDbName}" property="${keyName}" />
      <#else>
        <result column="${field.fieldDbName}" property="${field.fieldName}" />
      </#if>
    </#list>
    </resultMap>

    <${'!--'?html} 根据主键ID查询${className} ${'--'?html}>
    <${'!--'?html}
    <select id="selectPageByQuery" resultMap="${classObjectName}ResultMap" parameterType="${basePackage}.core.${moduleName}.dto.${className}PageQueryDTO">
    <#list fields as field>
        <#if field.fieldType == 'String'>
        <if test="null != ${field.fieldName} and '' != ${field.fieldName} ">
            <bind name="like_${field.fieldName}" value="'%' + ${field.fieldName} + '%'"/>
        </if>
        </#if>
    </#list>
        SELECT *
        FROM ${tableName}
        <where>
        <#list fields as field>
            <#if field.fieldType == 'String'>
            <if test="null != ${field.fieldName} and '' != ${field.fieldName} ">
                AND ${field.fieldDbName} like ${'#'?html}{like_${field.fieldName}}
            </if>
            <#else>
            <if test="null != ${field.fieldName}">
                AND ${field.fieldDbName} = ${'#'?html}{${field.fieldName}}
            </if>
            </#if>
        </#list>
        </where>
    </select>
    ${'--'?html}>

</mapper>